package kr.hkit.powerjava.chapter21.submit;

// 예외처리 프린트 프로그래밍 연습 2
class InvalidWithdraw extends Exception { // 새로운 예외구현
	private static final long serialVersionUID = 1L;

	public InvalidWithdraw(String message) {
		super(message);
	}
}

class Ex03 {
	private int balance;

	public Ex03(int balance) {
		this.balance = balance;
	}

	public Ex03() {
	}
	
	public int getBalance() {
		return balance;
	}

	public void setBalance(int balance) {
		this.balance = balance;
	}

	public int deposit(int money) { // 입금
		return balance += money;
	}

	public int withdraw(int money) throws InvalidWithdraw { // 출금

		if (money > balance)  { // 출금불가
			throw new InvalidWithdraw("초과 출금 요구 예외");
		}else {
			balance -= money;
			return money;
		}
	}
}
